<?php

require_once 'Constraint.php';

if (!defined("PHP_UI_PATH")) {
    define("PHP_UI_PATH", dirname(__FILE__));
}

if (!defined("DS")) {
    define("DS", DIRECTORY_SEPARATOR);
}

/**
 * Defines a User Interface control and it's behavior.
 *
 * @author Virtualidad
 */
abstract class UIControl {

    private $styleClasses = array("input");
    private $value = "";
    private $visible = true;
    private $name;
    private $id;
    private $required = false;
    /**
     *
     * @var Constraint
     */
    private $Constraint;

    public function getStyleClasses() {
        return implode(" ", $this->styleClasses);
    }

    protected abstract function getControlRendering();

    /**
     *
     * @return <type>
     * @deprecated Use the Constraint system instead.
     */
    protected function getScriptRendering() {
        return "";
    }

    public function display($output = true) {
        $render = $this->getControlRendering();
        if ($output) {
            echo $render;
        }

        return $render;
    }

    /**
     *
     * @param boolean $output If the script should be rendered inmediately.
     * @return string The rendered script. 
     * @deprecated Use de Constraint system instead
     */
    public function renderScript($output = true) {
        $render = $this->getScriptRendering();
        if ($output) {
            echo $render;
        }

        return $render;
    }

// <editor-fold defaultstate="collapsed" desc="Getters & Setters">
    public function getValue() {
        return $this->value;
    }

    public function setValue($value) {
        $this->value = $value;
    }

    public function getName() {
        return $this->name;
    }

    public function setName($name) {
        $this->name = $name;
    }

    public function getId() {
        return $this->id;
    }

    public function setId($id) {

        $this->id = $id;
    }

    public function getVisible() {
        return $this->visible;
    }

    public function setVisible($visible) {
        $this->visible = $visible;
    }

    public function addStyleClass($class) {
        $this->styleClasses[] = $class;
    }

    public function getRequired() {
        return $this->required;
    }

    public function setRequired($required) {
        $this->required = $required;
    }

    public function getConstraint() {
        return $this->Constraint;
    }

    public function setConstraint(Constraint $Constraint) {
        $this->Constraint = $Constraint;
        $this->addStyleClass($Constraint->getConstraintClass());
    }

    // </editor-fold>
}

?>
